home *** CD-ROM | disk | FTP | other *** search
/ FM Towns: Free Software Collection 7 / FM Towns Free Software Collection 7.iso / taropyon / znsplay / src / main.c < prev    next >
C/C++ Source or Header  |  1993-11-30  |  10KB  |  421 lines

  1. /*************************************************************************
  2. *    "ZNSPLAY"
  3. *************************************************************************/
  4.  
  5.  
  6. #include    <stdio.h>
  7. #include    <stdlib.h>
  8. #include    <ctype.h>
  9. #include    <string.h>
  10. #include    <time.h>
  11. #ifdef    __HIGHC__
  12. #    include    <heap.cf>
  13. #endif
  14.  
  15. #include    <egb.h>
  16. #include    <mos.h>
  17. #include    <snd.h>
  18. #include    <xld.h>
  19. #include    <sidework.h>
  20. #include    <loader.h>
  21.  
  22. #include    "znsplay.h"
  23. #include    "../dll/bgm/midi.h"
  24.  
  25. #include    <setint.h>
  26. #include    <doscons.h>
  27. #include    <spgetopt.h>
  28. #include    <fdl.h>
  29. #include    <fdl/fdlcol.h>
  30. #include    <dta.h>
  31. #include    <dtaname.h>
  32.  
  33. extern    int        SideWorkMenu(void);
  34.  
  35. static CONST char    RECODENAME_MAINARG[] = DTA_RECODENAME_MAINARG;
  36. DTACTRL_T            *DtaCtrl = NULL;
  37.  
  38. static    PLT_RGB    PltDat[16] =
  39. {
  40.     /* G R  B                                */
  41.     { 0, 0, 0},    /* C_BALCK                    */
  42.     { 0, 0, 0},    /* C_BLUE or C_THROUGH        */
  43.     { 7, 7, 8},    /* C_RED                    */
  44.     {12,12,13},    /* C_MAGENTA                */
  45.     { 6, 5, 7},    /* C_GREEN                    */
  46.     { 8, 7, 9},    /* C_CYAN                    */
  47.     {10, 9,11},    /* C_YELLOW                    */
  48.     {11,11,12},    /* C_WHITE                    */
  49.  
  50.     { 5, 5, 6},    /* C_HBALCK                    */
  51.     { 0, 0,11},    /* C_HBLUE                    */
  52.     { 0,11, 0},    /* C_HRED                    */
  53.     { 0,11,11},    /* C_HMAGENTA                */
  54.     {11, 0, 0},    /* C_HGEEN                    */
  55.     {11, 0,11},    /* C_HCYAN                    */
  56.     {11,11, 0},    /* C_HYELLOW                */
  57.     {14,14,15}    /* C_HWHITE                    */
  58. };
  59.  
  60.  
  61. POINT        DisplayStartPara[4] = 
  62. {
  63.     {0,0},        /* 画面の表示開始一の設定    */
  64.     {0,0},        /* 仮想画面中の移動            */
  65.     {2,2},        /* 画面の拡大                */
  66.     {320,240},    /* 表示画面の大きさ            */
  67. };
  68.  
  69. void    page1_palette(void)
  70. {
  71.     DSP_writePage(1);
  72.     DSP_setPlt(PltDat);
  73. }
  74.  
  75. void    ZNS_displayStart( int mode, int x, int y )
  76. {
  77.     DisplayStartPara[mode].x = x;
  78.     DisplayStartPara[mode].y = y;
  79.     EGB_displayStart(EgbPtr, mode, DisplayStartPara[mode].x,
  80.                                    DisplayStartPara[mode].y );
  81. }
  82.  
  83. #if    0
  84. void    reinit(void)
  85. {
  86.     int        page;
  87.  
  88.     {
  89.         int        i;
  90.         page = 0;
  91.         for ( i = 0; i < 4; ++i )
  92.         {
  93.             EGB_displayStart(EgbPtr, i, DisplayStartPara[i].x,
  94.                                         DisplayStartPara[i].y );
  95.         }
  96.     }
  97.     {
  98.         page = 1;
  99.         EGB_writePage(EgbPtr, page );
  100.         EGB_displayStart(EgbPtr, 1, DspCtrl.scinf[page].dspstart.x,
  101.                                     DspCtrl.scinf[page].dspstart.y );
  102.         EGB_displayStart(EgbPtr, 3, DspCtrl.scinf[page].sc.x2+1,
  103.                                     DspCtrl.scinf[page].sc.y2+1 );
  104.     }
  105.  
  106.     MOS_setControl(0x7F);
  107.     MOS_resolution(0,DspCtrl.page0);
  108.     MOS_resolution(1,DspCtrl.page1);
  109.     MOS_writePage(MosInf.page);
  110.     MOS_curType( 81 );
  111.     MosInf.move = DspCtrl.scinf[MosInf.page].sc;
  112.     MOS_moveArea( MosInf.move.x1, MosInf.move.y1,
  113.                   MosInf.move.x2, MosInf.move.y2 );
  114.  
  115.     page1_palette();
  116. }
  117. #endif
  118.  
  119. /*************************************************************************
  120. *    システム初期化
  121. *************************************************************************/
  122. static    int        init( int *argc, char **argv[], int _argc, char **_argv )
  123. {
  124.     DTARECODE_T    *arg_recode = NULL;
  125.  
  126. #ifdef    __HIGHC__
  127.     /* メモリ取得用設定    */
  128.     Init_allocated_storage = 0;
  129. #endif
  130.  
  131.     *argc = _argc;
  132.     *argv = _argv;
  133.     if ( DTA_isAtPcl() )
  134.     {
  135.         /* 子プロセス起動    */
  136.         char        *args = "ZNSPLAY";
  137.  
  138.         if ( (DtaCtrl = DTA_openCheck()) != NULL )
  139.         {
  140.             if ( (arg_recode = DTA_openRecode( DtaCtrl, RECODENAME_MAINARG)) != NULL )
  141.             {    /* パラメータの指定あり    */
  142.                 args = arg_recode->ptr;
  143.             }
  144.         }
  145.         if ( (*argc = FS_argSet( args, argv )) < 1 )
  146.             return (ERR);
  147.     }
  148.  
  149.     set_ctrl_c();
  150.     set24h();
  151.  
  152.     if ( SndPtr == NULL )
  153.     {
  154.         if ( (SndPtr = calloc(16384,1)) == NULL )
  155.         {
  156.             reset24h();
  157.             return (ERR);
  158.         }
  159.         SND_init( SndPtr );
  160.     }
  161.  
  162.     DSPCTRL            dsp;
  163.  
  164.     dsp = DspCtrl;
  165.     dsp.page0              = ZNS_RESOLUSION;
  166.     dsp.scinf[0].md        = ZNS_RESOLUSION;
  167.  
  168.     dsp.scinf[0].fr.x1      = 0;
  169.     dsp.scinf[0].fr.y1      = 0;
  170.     dsp.scinf[0].fr.x2      = 511;
  171.     dsp.scinf[0].fr.y2      = 255;
  172.     dsp.scinf[0].sc.x1      = 0;
  173.     dsp.scinf[0].sc.y1      = 0;
  174.     dsp.scinf[0].sc.x2      = 319;
  175.     dsp.scinf[0].sc.y2      = 239;
  176.     dsp.scinf[0].view.x1    = 0;
  177.     dsp.scinf[0].view.y1    = 0;
  178.     dsp.scinf[0].view.x2    = 319;
  179.     dsp.scinf[0].view.y2    = 239;
  180.     dsp.scinf[0].dlgArea.x1 = 2;
  181.     dsp.scinf[0].dlgArea.y1 = 14;
  182.     dsp.scinf[0].dlgArea.x2 = 319-2;
  183.     dsp.scinf[0].dlgArea.y2 = 239-10;
  184.     MosInf.scrollPage = 0xFF;        /* スクロールなし    */
  185.     DSP_sysInit( &dsp );
  186.  
  187.     DSP_set_defFnt( FNTYPE_USR1 );
  188.     GetFnt12Ptr(0);                /* ank font 12 初期設定        */
  189.     KBF_sysInit();                /* キーボードシステム初期化    */
  190.     KBF_kan_off();                /* かな漢字変換禁止            */
  191.     FDL_sysInit();                /* ファイルダイアログ        */
  192.     sdk_control(0);                /* サイドワーク起動禁止        */
  193.  
  194.     /* DLL システム初期化    */
  195.     _XLD_init(NULL);
  196.     _XLD_setMemFunc( malloc, free );
  197.     {
  198.         char    tmp[256];
  199.         int        len;
  200.         FS_setStartPath( tmp, *argv[0] );
  201.         if ( (len = strlen(tmp)) > 0 )
  202.             tmp[--len] = '\0';
  203.         _XLD_setLinkPath( tmp );
  204.     }
  205.     _XLD_lockLib( MID_playStatFlag );
  206.  
  207.     /* MIDI BGM システム初期化    */
  208.     MID_sysInit();
  209.  
  210.     /* パレット設定    */
  211.     DSP_writePage(1);
  212.     DSP_setPlt(PltDat);
  213.  
  214.     /*    タイトル表示    */
  215.     DSP_writePage(1);
  216.     DSP_title( _ZNSPLAY_, MAIN_VER, C_HWHITE, C_WHITE, C_MBLACK, C_HBLACK );
  217.  
  218.     /* ファイルダイアログ    */
  219.     FdlDefColTbl[0] = C_DLGBASE;
  220.     Fdl_set_doscall( DOScons_open, DOScons_close, system);
  221.     Fdl_set_sidework( SideWorkMenu );
  222.     FdlSetWildCardList( ZNS_WILD_ALL );
  223.     FdlSetWildCardList( ZNS_WILD_MOV );
  224. /*    FdlSetWildCardList( ZNS_WILD_V00 );    */
  225.     FdlSetWildCardList( ZNS_WILD_V02 );
  226.  
  227.     return (NORMAL);
  228. }
  229.  
  230. static    void    term(void)
  231. {
  232.     MID_sysEnd();
  233.     FDL_sysEnd();
  234.     KBF_sysEnd();
  235.     DSP_sysEnd();
  236.  
  237.     if ( SndPtr )
  238.     {
  239.         SND_end();
  240.         free(SndPtr);
  241.         SndPtr = NULL;
  242.     }
  243.  
  244.     reset24h();
  245. }
  246.  
  247. static    void    help(void)
  248. {
  249.     static CONST char    help_msg[] = "\
  250.      usage : znsplay [<option>] [<filename>]    \n\
  251.      <option>                                   \n\
  252.        -wait <n>    ... wait time (n:0~99)     \n\
  253.        -display <n> ... display mode (n:1~4)   \n\
  254.        -disk        ... disk play mode          \n\
  255.        -memory      ... memory play mode        \n\
  256.        -chkPort <right/left/both>               \n\
  257.                     ... pause & stop check port \
  258. ";
  259.  
  260.     DSP_writePage(1);
  261.     DLG_tmpMsgBox ( DLGPOS_CENTER_OF_SCN, DLGPOS_CENTER_OF_SCN,
  262.         DspCtrl.black, C_DLGBASE, COLMIX(C_INFO,C_GRAY),
  263.         "“UGOKUZANSU” movie data player  %s ver.%s\n\n%s",
  264.         _ZNSPLAY_, MAIN_VER, help_msg );
  265.  
  266. }
  267.  
  268. static    int        errFunc( CONST char *s )
  269. {
  270.     /* return (-1) 即中断               */
  271.     /* return (1)  エラーは無視して中断 */
  272.     /* return (0)  エラーは無視         */
  273.  
  274.     return (0);
  275. }
  276.  
  277. /*************************************************************************
  278. *    オプションパラメータの解析/設定
  279. *************************************************************************/
  280. static    int        set_option( int argc, char **argv )
  281. {
  282.     static    int            helpVar    = 0;
  283.     static    GOP_DIGIT_T    waitPar    = { 0, 0, 99 };
  284.     static    GOP_DIGIT_T    displayPar = { 1, 1, 4 };
  285.     static    int            memoryVar  = 0;
  286.     static    int            diskVar    = 0;
  287.     extern    int            ZnsSwPort;
  288.     static    GOP_SELECT_OBJ_T    ZnsSwPortObj[3] =
  289.     {
  290.         {1,"left" },
  291.         {2,"right"},
  292.         {3,"both" },
  293.     };
  294.     static    GOP_SELECT_T    ZnsSwPortPar = {3, ZnsSwPortObj};
  295.  
  296.     static    GOPKEY_T    GetoptKey[] = 
  297.     {
  298.         { GOP_TYP_FLAG  , "?"             , GOP_VAR_INT , &helpVar             , NULL         },
  299.         { GOP_TYP_DIGIT , "wait"          , GOP_VAR_INT , &ZnsMove.wait        , &waitPar     },
  300.         { GOP_TYP_DIGIT , "display"       , GOP_VAR_INT , &ZnsMove.expand      , &displayPar  },
  301.         { GOP_TYP_FLAG  , "memory"        , GOP_VAR_INT , &memoryVar           , NULL         },
  302.         { GOP_TYP_FLAG  , "disk"          , GOP_VAR_INT , &diskVar             , NULL         },
  303.         { GOP_TYP_SELECT, "chkPort"       , GOP_VAR_INT , &ZnsSwPort           , &ZnsSwPortPar},
  304.         { -1            ,  NULL           , 0           , NULL                 , NULL         },
  305.     };
  306.     GOP_T    gop = {GOP_MODE_NORMAL,"-/",GetoptKey,errFunc,0,NULL};
  307.  
  308.     if ( argc < 2 )
  309.         return (NORMAL);
  310.  
  311.     if ( GOP_decode(&gop,argc-1,&argv[1]) == NORMAL )
  312.     {
  313.         if ( helpVar )
  314.             help();
  315.         if ( memoryVar )
  316.             ZnsMove.mode = ZNS_MODE_MEMORY;
  317.         else if ( diskVar )
  318.             ZnsMove.mode = ZNS_MODE_DISK;
  319.  
  320.         {
  321.             GOPETC_T    *etc = gop.etc;
  322.             if ( etc && etc->s[0] )
  323.                 strcpy( ZnsMove.filename, etc->s );
  324.         }
  325.     }
  326.     GOP_free( &gop );
  327.  
  328.     return (NORMAL);
  329. }
  330. #if    0
  331. static    int        set_option( int argc, char **argv )
  332. {
  333.     int            i, mm;
  334.     char        *s;
  335.     int            nextopt(void)
  336.     {
  337.         if ( ++i == argc )
  338.             return (-1);
  339.         s = argv[i];
  340.         if ( *s == '?' || *s == '-' || *s == '/' )
  341.              return (1);
  342.         return (0);
  343.     };
  344. #define    CHKNEXT()    if((mm=nextopt())<0){goto L_END;}else if(mm>0){goto L_NEXT;}
  345.     int        help_flag = FALSE;
  346.  
  347.     for ( i = 1; i < argc; ++i )
  348.     {
  349.         s = argv[i];
  350. L_NEXT:
  351.         if ( *s == '?' )
  352.         {
  353.             help_flag = TRUE;
  354.         } else if ( *s == '-' || *s == '/' )
  355.         {    
  356.             ++s;
  357.             if ( *s == '?' )
  358.             {
  359.                 help_flag = TRUE;
  360.             } else if ( strcmpi( s, "wait") == 0 )
  361.             {
  362.                 int        wait;
  363.                 ZnsMove.wait = 0;
  364.                 CHKNEXT();
  365.                 wait = atoi(s);
  366.                 if ( wait >= 0 && wait <= 99 )
  367.                     ZnsMove.wait = wait;
  368.             } else if ( strcmpi( s, "display") == 0 )
  369.             {
  370.                 int        expand;
  371.                 ZnsMove.expand = 1;
  372.                 CHKNEXT();
  373.                 expand = atoi(s);
  374.                 if ( expand >= 1 && expand <= 4 )
  375.                     ZnsMove.expand = expand;
  376.             } else if ( strcmpi( s, "disk") == 0 )
  377.             {
  378.                 ZnsMove.mode = ZNS_MODE_DISK;
  379.             } else if ( strcmpi( s, "memory") == 0 )
  380.             {
  381.                 ZnsMove.mode = ZNS_MODE_MEMORY;
  382.             }
  383.         } else if ( ZnsMove.filename[0] == '\0' )
  384.         {
  385.             strcpy( ZnsMove.filename, s );
  386.         }
  387.     }
  388. L_END:
  389.     if ( help_flag )
  390.         help();
  391.     return (NORMAL);
  392. }
  393. #endif
  394.  
  395. void    main(int _argc, char *_argv[])
  396. {
  397.     int            ret;
  398.     int         argc;
  399.     char        **argv;
  400.  
  401.     if ( init(&argc,&argv,_argc,_argv) )
  402.     {
  403.         ret = 1;
  404.     } else
  405.     {
  406.         if ( argc > 1 && set_option(argc,argv) )
  407.         {
  408.             ret = 1;
  409.         } else
  410.         {
  411.             zns_main();
  412.             ret = 0;
  413.         }
  414.         term();
  415.     }
  416.  
  417.     pcl_exit(0);
  418.     exit(ret);
  419. }
  420.  
  421.